VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "EventLogger"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private LocalServer As String
Private BufferSize As Long

Public Enum eSource
  eSuccess = 0
  eError = 1
  eWarning = 2
  eInformation = 4
  
End Enum

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function LogEvent(EventText As String, Severity As eSource, Source As String, Optional Server As String, _
                        Optional CategoryNumber As Long, Optional EventID As Long) As Boolean
  Dim sCategoryNumber As String
  Dim sEventID As String
  Dim sSeverity As String
  
  Dim WshShell As New WshShell
  
                      
 On Error GoTo ErrorHandler
 
  EventText = App.EXEName & "::" & EventText
  
  If Len(Server) = 0 Then
    Server = "\\" & LocalServer
  Else
     Server = "\\" & Server
  End If
  

  
   If WshShell.LogEvent(Severity, EventText, Server) Then
     LogEvent = True
  Else
    LogEvent = False
  End If
  
ErrorHandler:
    If Err.Number <> 0 Then
        Debug.Print "Error with Event Logger"
        Debug.Print Err.Description
        Err.Clear
        LogEvent = False
    End If
End Function

Private Sub Class_Initialize()
  BufferSize = 255
  LocalServer = Space$(BufferSize)
  GetComputerName LocalServer, BufferSize
  LocalServer = Trim(LocalServer)
  LocalServer = Mid(LocalServer, 1, Len(LocalServer) - 1)
End Sub


'Usage: logevent [-m \\MACHINENAME] [-s Severity] [-c CategoryNumber]
'        [-r Source] [-e EventID] [-t TimeOut] "Event Text"
'        Severity is one of (S)uccess, (I)nformation, (W)arning,
'                           (E)rror or (F)ailure.
'        Source is a string (can be quoted) for the event's source.
'        EventID is an integer for the event's Event ID (0-65535).
'        TimeOut is the number of seconds the system waits before exit.
'
'Default Values:
'        If -s isn't specified, default is "Information".
'        If -c isn't specified, default is 0.
'        If -r isn't specified, default is "User Event".
'        If -e isn't specified, default is 1.
'        If -t isn't specified, default is 60000.
'
'Example:
'        logevent -m \\server -s E -c 3 -r "User Event" -e 42
'        "My message."
'
'Note:
'        Names that include space characters must be enclosed in double quotes


Private Sub Class_Terminate()

End Sub


